<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
    <form id="loginFrom" onsubmit="return false">
        用户名：<input type="text" name="tname"> <br> </br></input>
        密码：<input type="password" name="tpwd"> <br> </br></input>
        <input type="button" value="登录" onclick="login()"></input>
    </form>
<script>
    function login() {
        //var data=$("#loginFrom").serialize();
        $.ajax({
            url:"/login",
            data:$("#loginFrom").serialize(),
            type:"post",
            success:function (data){
                if (data.code==200){
                    window.location.href="/index";
                }else if (data.code==400){
                    alert(data.msg);
                }
            },
            error:function (data){
                alert(data.msg);
            }
        })
    }
</script>
</body>
</html>